home *** CD-ROM | disk | FTP | other *** search
/ Tech Arsenal 1 / Tech Arsenal (Arsenal Computer).ISO / tek-01 / readndx.zip / READNDX.C < prev    next >
C/C++ Source or Header  |  1993-01-04  |  2KB  |  102 lines

  1. /*
  2. readndx.c:  spits out some info about dBase III Plus NDX files
  3. Andrew Schulman 1/4/88, revised 1/14/88
  4. 12 Humboldt St., Cambridge MA 02140
  5.  
  6. compiled with MSC 5.0:
  7.         cl -Zpe -Ox -Gs readndx.c \msc5\lib\ssetargv.obj
  8. ssetargv.obj takes care of wildcard expansion
  9.  
  10. based on information supplied by Pete Olympia.  Thanks, Pete!
  11. and by information from Curtis H. Hoffman (".DBF and .NDX Header Definitions")
  12. */
  13.  
  14. #include <stdio.h>
  15. #include <string.h>
  16. #include <dos.h>
  17. #include <fcntl.h>
  18.  
  19. #define MAXKEYLEN    100
  20.  
  21. typedef unsigned char BYTE;
  22. typedef unsigned long DWORD;
  23.  
  24. typedef struct
  25. {
  26.     DWORD rootnode;
  27.     DWORD nextnode;
  28.     DWORD pad1;
  29.     BYTE keylen, pad2;
  30.     BYTE keypernode, pad3;
  31.     BYTE numeric, pad4;
  32.     BYTE sizekeyentry;
  33.     char pad5[5];
  34.     char expression[MAXKEYLEN];
  35.     char pad6[512-124];
  36.     BYTE numentries;
  37.     char pad7[3];
  38. } NDX_HEAD;
  39.  
  40. NDX_HEAD ndx;
  41.  
  42. main(argc, argv)
  43.     int argc;
  44.     char *argv[];
  45. {
  46.     register int i;
  47.  
  48.     if (argc<2)    {
  49.         printf("READNDX reads dBase III Plus NDX files. Big deal!\n");
  50.         printf("examples:\n\tREADNDX inv1987.*\n\tREADNDX *.*\n\tREADNDX *.NDX\n");
  51.         exit(1);
  52.         }
  53.     
  54.     for (i=1; i<argc; i++)    {
  55.         readndx(argv[i]);
  56.         printf("\n");
  57.         }
  58.     
  59.     exit(0);
  60. }
  61.  
  62. readndx(s)
  63.     char *s;
  64. {
  65.     char file[80];
  66.     unsigned int f, count;
  67.     
  68.     strcpy(file,strupr(s));
  69.     if (! strchr(file, '.')) strcat(file, ".NDX");
  70.     
  71.     if (_dos_open(file, O_RDONLY | O_BINARY, &f) != 0)    {
  72.         printf("READNDX cannot open file (%s)\n", file);
  73.         return;
  74.         }
  75.  
  76.     if (_dos_read(f, (void far *)&ndx, sizeof(NDX_HEAD), &count) != 0)    {
  77.         printf("Can't read from file (%s)\n", file);
  78.         return;
  79.         }
  80.  
  81. /***
  82.     THIS IS THE BIG TEST TO DETERMINE IF IT'S A DBASE NDX FILE (THE NDX
  83.     EXTENSION DOESN'T MEAN IT IS; AND THE LACK OF ONE DOESN'T MEAN IT ISN'T)
  84. ***/         
  85.     if (! ndx.sizekeyentry || ndx.keypernode != (508 / ndx.sizekeyentry))    {
  86.         printf("Not a dBase III Plus index file (%s)\n", file);
  87.         return;
  88.         }
  89.         
  90.     printf("dBase III Plus index file %s\n", file);
  91.     printf("key expression: \"%s\"\n", ndx.expression);
  92.     printf("rootnode: %lu\n", ndx.rootnode);
  93.     printf("nextnode: %lu\n", ndx.nextnode);
  94.     printf("keylen: %d\n", ndx.keylen);
  95.     printf("keypernode: %d\n", ndx.keypernode);
  96.     printf("numeric flag: %d\n", ndx.numeric);
  97.     printf("sizekeyentry: %d\n", ndx.sizekeyentry);
  98.     printf("root node num entries: %d\n", ndx.numentries);
  99.     
  100.     _dos_close(f);
  101. }    
  102.